package com.ai.dao;

import java.sql.SQLException;

import com.ai.dbutil.DBconn;
import com.ai.entity.Coach;
import com.ai.entity.Member;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;

public class CoachDao {
	/*
	 * if success returns affected rows in database which is positive,
	 * else returns 0.
	 */
	public int addCoach(Coach coach) {
		Connection conn = DBconn.getInstance();
		int i = 0;
		String sql = "insert into coach (COACHNAME, FAMILY, AGE, ADVANTAGE)"
				+ " values (?,?,?,?)";
		PreparedStatement pstmt;
		try {
	        pstmt = (PreparedStatement) conn.prepareStatement(sql);
	        pstmt.setString(1, coach.getCoachName());
	        pstmt.setString(2, coach.getFamily());
	        pstmt.setInt(3, coach.getAge());
	        pstmt.setString(4, coach.getAdvantage());
	        i = pstmt.executeUpdate();
	        pstmt.close();
	        conn.close();
	    } catch (SQLException e) {
	        e.printStackTrace();
	    }	
	    return i;
	}
}
